﻿namespace com.vs.DataAccess
{
    using com.vs.General;
    using System;
    using System.Data;

    public class DataManager
    {
        private static bool GetBool(string val)
        {
            return StringManager.Equals(val, "Y", true);
        }

        public static bool GetBool(DataRow row, int columnIndex)
        {
            return GetBool(GetString(row, columnIndex));
        }

        public static bool GetBool(DataRow row, string columnName)
        {
            return GetBool(GetString(row, columnName));
        }

        public static bool GetBool(DataRowView row, int columnIndex)
        {
            return GetBool(GetString(row, columnIndex));
        }

        public static bool GetBool(DataRowView row, string columnName)
        {
            return GetBool(GetString(row, columnName));
        }

        public static bool GetBool(IDataReader reader, int columnIndex)
        {
            return GetBool(GetString(reader, columnIndex));
        }

        public static bool GetBool(IDataReader reader, string columnName)
        {
            return GetBool(GetString(reader, columnName));
        }

        public static bool GetBool(DataTable table, int rowIndex, int columnIndex)
        {
            return GetBool(table.Rows[rowIndex], columnIndex);
        }

        public static bool GetBool(DataTable table, int rowIndex, string columnName)
        {
            return GetBool(table.Rows[rowIndex], columnName);
        }

        public static bool GetBool(DataView view, int rowIndex, int columnIndex)
        {
            return GetBool(view[rowIndex], columnIndex);
        }

        public static bool GetBool(DataView view, int rowIndex, string columnName)
        {
            return GetBool(view[rowIndex], columnName);
        }

        private static DateTime GetDateTime(object o)
        {
            return ((o == null) ? DateTime.MinValue : Convert.ToDateTime(o));
        }

        public static DateTime GetDateTime(DataRow row, int columnIndex)
        {
            return GetDateTime(UnMask(row[columnIndex]));
        }

        public static DateTime GetDateTime(DataRow row, string columnName)
        {
            return GetDateTime(UnMask(row[columnName]));
        }

        public static DateTime GetDateTime(DataRowView row, int columnIndex)
        {
            return GetDateTime(UnMask(row[columnIndex]));
        }

        public static DateTime GetDateTime(DataRowView row, string columnName)
        {
            return GetDateTime(UnMask(row[columnName]));
        }

        public static DateTime GetDateTime(IDataReader reader, int columnIndex)
        {
            return GetDateTime(UnMask(reader[columnIndex]));
        }

        public static DateTime GetDateTime(IDataReader reader, string columnName)
        {
            return GetDateTime(UnMask(reader[columnName]));
        }

        public static DateTime GetDateTime(DataTable table, int rowIndex, int columnIndex)
        {
            return GetDateTime(table.Rows[rowIndex], columnIndex);
        }

        public static DateTime GetDateTime(DataTable table, int rowIndex, string columnName)
        {
            return GetDateTime(table.Rows[rowIndex], columnName);
        }

        public static DateTime GetDateTime(DataView view, int rowIndex, int columnIndex)
        {
            return GetDateTime(view[rowIndex], columnIndex);
        }

        public static DateTime GetDateTime(DataView view, int rowIndex, string columnName)
        {
            return GetDateTime(view[rowIndex], columnName);
        }

        private static decimal GetDecimal(object o)
        {
            return ((o == null) ? 0M : Convert.ToDecimal(o));
        }

        public static decimal GetDecimal(DataRow row, int columnIndex)
        {
            return GetDecimal(UnMask(row[columnIndex]));
        }

        public static decimal GetDecimal(DataRow row, string columnName)
        {
            return GetDecimal(UnMask(row[columnName]));
        }

        public static decimal GetDecimal(DataRowView row, int columnIndex)
        {
            return GetDecimal(UnMask(row[columnIndex]));
        }

        public static decimal GetDecimal(DataRowView row, string columnName)
        {
            return GetDecimal(UnMask(row[columnName]));
        }

        public static decimal GetDecimal(IDataReader reader, int columnIndex)
        {
            return GetDecimal(UnMask(reader[columnIndex]));
        }

        public static decimal GetDecimal(IDataReader reader, string columnName)
        {
            return GetDecimal(UnMask(reader[columnName]));
        }

        public static decimal GetDecimal(DataTable table, int rowIndex, int columnIndex)
        {
            return GetDecimal(table.Rows[rowIndex], columnIndex);
        }

        public static decimal GetDecimal(DataTable table, int rowIndex, string columnName)
        {
            return GetDecimal(table.Rows[rowIndex], columnName);
        }

        public static decimal GetDecimal(DataView view, int rowIndex, int columnIndex)
        {
            return GetDecimal(view[rowIndex], columnIndex);
        }

        public static decimal GetDecimal(DataView view, int rowIndex, string columnName)
        {
            return GetDecimal(view[rowIndex], columnName);
        }

        private static double GetDouble(object o)
        {
            return ((o == null) ? 0.0 : Convert.ToDouble(o));
        }

        public static double GetDouble(DataRow row, int columnIndex)
        {
            return GetDouble(UnMask(row[columnIndex]));
        }

        public static double GetDouble(DataRow row, string columnName)
        {
            return GetDouble(UnMask(row[columnName]));
        }

        public static double GetDouble(DataRowView row, int columnIndex)
        {
            return GetDouble(UnMask(row[columnIndex]));
        }

        public static double GetDouble(DataRowView row, string columnName)
        {
            return GetDouble(UnMask(row[columnName]));
        }

        public static double GetDouble(IDataReader reader, int columnIndex)
        {
            return GetDouble(UnMask(reader[columnIndex]));
        }

        public static double GetDouble(IDataReader reader, string columnName)
        {
            return GetDouble(UnMask(reader[columnName]));
        }

        public static double GetDouble(DataTable table, int rowIndex, int columnIndex)
        {
            return GetDouble(table.Rows[rowIndex], columnIndex);
        }

        public static double GetDouble(DataTable table, int rowIndex, string columnName)
        {
            return GetDouble(table.Rows[rowIndex], columnName);
        }

        public static double GetDouble(DataView view, int rowIndex, int columnIndex)
        {
            return GetDouble(view[rowIndex], columnIndex);
        }

        public static double GetDouble(DataView view, int rowIndex, string columnName)
        {
            return GetDouble(view[rowIndex], columnName);
        }

        private static int GetInt(object o)
        {
            return ((o == null) ? 0 : Convert.ToInt32(o));
        }

        public static int GetInt(DataRow row, int columnIndex)
        {
            return GetInt(UnMask(row[columnIndex]));
        }

        public static int GetInt(DataRow row, string columnName)
        {
            return GetInt(UnMask(row[columnName]));
        }

        public static int GetInt(DataRowView row, int columnIndex)
        {
            return GetInt(UnMask(row[columnIndex]));
        }

        public static int GetInt(DataRowView row, string columnName)
        {
            return GetInt(UnMask(row[columnName]));
        }

        public static int GetInt(IDataReader reader, int columnIndex)
        {
            return GetInt(UnMask(reader[columnIndex]));
        }

        public static int GetInt(IDataReader reader, string columnName)
        {
            return GetInt(UnMask(reader[columnName]));
        }

        public static int GetInt(DataTable table, int rowIndex, int columnIndex)
        {
            return GetInt(table.Rows[rowIndex], columnIndex);
        }

        public static int GetInt(DataTable table, int rowIndex, string columnName)
        {
            return GetInt(table.Rows[rowIndex], columnName);
        }

        public static int GetInt(DataView view, int rowIndex, int columnIndex)
        {
            return GetInt(view[rowIndex], columnIndex);
        }

        public static int GetInt(DataView view, int rowIndex, string columnName)
        {
            return GetInt(view[rowIndex], columnName);
        }

        private static long GetLong(object o)
        {
            return ((o == null) ? 0 : Convert.ToInt64(o));
        }

        public static long GetLong(DataRow row, int columnIndex)
        {
            return GetLong(UnMask(row[columnIndex]));
        }

        public static long GetLong(DataRow row, string columnName)
        {
            return GetLong(UnMask(row[columnName]));
        }

        public static long GetLong(DataRowView row, int columnIndex)
        {
            return GetLong(UnMask(row[columnIndex]));
        }

        public static long GetLong(DataRowView row, string columnName)
        {
            return GetLong(UnMask(row[columnName]));
        }

        public static long GetLong(IDataReader reader, int columnIndex)
        {
            return GetLong(UnMask(reader[columnIndex]));
        }

        public static long GetLong(IDataReader reader, string columnName)
        {
            return GetLong(UnMask(reader[columnName]));
        }

        public static long GetLong(DataTable table, int rowIndex, int columnIndex)
        {
            return GetLong(table.Rows[rowIndex], columnIndex);
        }

        public static long GetLong(DataTable table, int rowIndex, string columnName)
        {
            return GetLong(table.Rows[rowIndex], columnName);
        }

        public static long GetLong(DataView view, int rowIndex, int columnIndex)
        {
            return GetLong(view[rowIndex], columnIndex);
        }

        public static long GetLong(DataView view, int rowIndex, string columnName)
        {
            return GetLong(view[rowIndex], columnName);
        }

        public static object GetObject(DataRow row, int columnIndex)
        {
            return UnMask(row[columnIndex]);
        }

        public static object GetObject(DataRow row, string columnName)
        {
            return UnMask(row[columnName]);
        }

        public static object GetObject(DataRowView row, int columnIndex)
        {
            return UnMask(row[columnIndex]);
        }

        public static object GetObject(DataRowView row, string columnName)
        {
            return UnMask(row[columnName]);
        }

        public static object GetObject(IDataReader reader, int columnIndex)
        {
            return UnMask(reader[columnIndex]);
        }

        public static object GetObject(IDataReader reader, string columnName)
        {
            return UnMask(reader[columnName]);
        }

        public static object GetObject(DataTable table, int rowIndex, int columnIndex)
        {
            return GetObject(table.Rows[rowIndex], columnIndex);
        }

        public static object GetObject(DataTable table, int rowIndex, string columnName)
        {
            return GetObject(table.Rows[rowIndex], columnName);
        }

        public static object GetObject(DataView view, int rowIndex, int columnIndex)
        {
            return GetObject(view[rowIndex], columnIndex);
        }

        public static object GetObject(DataView view, int rowIndex, string columnName)
        {
            return GetObject(view[rowIndex], columnName);
        }

        private static string GetString(object o)
        {
            return ((o == null) ? "" : Convert.ToString(o));
        }

        public static string GetString(DataRow row, int columnIndex)
        {
            return GetString(UnMask(row[columnIndex]));
        }

        public static string GetString(DataRow row, string columnName)
        {
            return GetString(UnMask(row[columnName]));
        }

        public static string GetString(DataRowView row, int columnIndex)
        {
            return GetString(UnMask(row[columnIndex]));
        }

        public static string GetString(DataRowView row, string columnName)
        {
            return GetString(UnMask(row[columnName]));
        }

        public static string GetString(IDataReader reader, int columnIndex)
        {
            return GetString(UnMask(reader[columnIndex]));
        }

        public static string GetString(IDataReader reader, string columnName)
        {
            return GetString(UnMask(reader[columnName]));
        }

        public static string GetString(DataTable table, int rowIndex, int columnIndex)
        {
            return GetString(table.Rows[rowIndex], columnIndex);
        }

        public static string GetString(DataTable table, int rowIndex, string columnName)
        {
            return GetString(table.Rows[rowIndex], columnName);
        }

        public static string GetString(DataView view, int rowIndex, int columnIndex)
        {
            return GetString(view[rowIndex], columnIndex);
        }

        public static string GetString(DataView view, int rowIndex, string columnName)
        {
            return GetString(view[rowIndex], columnName);
        }

        public static bool IsEmpty(DataTable table)
        {
            return ((table == null) || (table.Rows.Count == 0));
        }

        public static bool IsEmpty(DataView view)
        {
            return ((view == null) || (view.Count == 0));
        }

        public static void SetBool(DataRow row, int columnIndex, bool val)
        {
            row[columnIndex] = val;
        }

        public static void SetBool(DataRow row, string columnName, bool val)
        {
            row[columnName] = val;
        }

        public static void SetBool(DataTable table, int rowIndex, int columnIndex, bool val)
        {
            SetBool(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetBool(DataTable table, int rowIndex, string columnName, bool val)
        {
            SetBool(table.Rows[rowIndex], columnName, val);
        }

        public static void SetDateTime(DataRow row, int columnIndex, DateTime val)
        {
            row[columnIndex] = val;
        }

        public static void SetDateTime(DataRow row, string columnName, DateTime val)
        {
            row[columnName] = val;
        }

        public static void SetDateTime(DataTable table, int rowIndex, int columnIndex, DateTime val)
        {
            SetDateTime(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetDateTime(DataTable table, int rowIndex, string columnName, DateTime val)
        {
            SetDateTime(table.Rows[rowIndex], columnName, val);
        }

        public static void SetDecimal(DataRow row, int columnIndex, decimal val)
        {
            row[columnIndex] = val;
        }

        public static void SetDecimal(DataRow row, string columnName, decimal val)
        {
            row[columnName] = val;
        }

        public static void SetDecimal(DataTable table, int rowIndex, int columnIndex, decimal val)
        {
            SetDecimal(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetDecimal(DataTable table, int rowIndex, string columnName, decimal val)
        {
            SetDecimal(table.Rows[rowIndex], columnName, val);
        }

        public static void SetDouble(DataRow row, int columnIndex, double val)
        {
            row[columnIndex] = Convert.ToDecimal(val);
        }

        public static void SetDouble(DataRow row, string columnName, double val)
        {
            row[columnName] = Convert.ToDecimal(val);
        }

        public static void SetDouble(DataTable table, int rowIndex, int columnIndex, double val)
        {
            SetDouble(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetDouble(DataTable table, int rowIndex, string columnName, double val)
        {
            SetDouble(table.Rows[rowIndex], columnName, val);
        }

        public static void SetInt(DataRow row, int columnIndex, int val)
        {
            row[columnIndex] = val;
        }

        public static void SetInt(DataRow row, string columnName, int val)
        {
            row[columnName] = val;
        }

        public static void SetInt(DataTable table, int rowIndex, int columnIndex, int val)
        {
            SetInt(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetInt(DataTable table, int rowIndex, string columnName, int val)
        {
            SetInt(table.Rows[rowIndex], columnName, val);
        }

        public static void SetLong(DataRow row, int columnIndex, long val)
        {
            row[columnIndex] = val;
        }

        public static void SetLong(DataRow row, string columnName, long val)
        {
            row[columnName] = val;
        }

        public static void SetLong(DataTable table, int rowIndex, int columnIndex, long val)
        {
            SetLong(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetLong(DataTable table, int rowIndex, string columnName, long val)
        {
            SetLong(table.Rows[rowIndex], columnName, val);
        }

        public static void SetString(DataRow row, int columnIndex, string val)
        {
            row[columnIndex] = val;
        }

        public static void SetString(DataRow row, string columnName, string val)
        {
            row[columnName] = val;
        }

        public static void SetString(DataTable table, int rowIndex, int columnIndex, string val)
        {
            SetString(table.Rows[rowIndex], columnIndex, val);
        }

        public static void SetString(DataTable table, int rowIndex, string columnName, string val)
        {
            SetString(table.Rows[rowIndex], columnName, val);
        }

        private static object UnMask(object o)
        {
            return ((o == DBNull.Value) ? null : o);
        }
    }
}

